var fectureArray=new Array();
fectureArray=["请选择"];

function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,'');
  }//去掉空格

function setSecondClass(val) {
	var cust_id = document.getElementById("cust_id").value;
	
	if(document.getElementById("sort1").value == ""){
		document.getElementById("sort2").style.display = "none";
		document.getElementById("sort3").style.display = "none";
		document.getElementById("sort1").value = "";
		document.getElementById("sort2").value = "";
		document.getElementById("sort3").value = "";
	}else{
		Ti_organizeInfo.getOrganizeByUpId(cust_id, val, setSort2);
	}
}

function setSort2(map_data) {
	var up_org_id = document.getElementById("sort1").value;
	var cust_id = document.getElementById("cust_id").value;
	if (map_data != null) {
		Ti_organizeInfo.checkChildren(cust_id,up_org_id,function(ret){
		 if(ret == "0"){
		 }else{
		 	 	DWRUtil.removeAllOptions("sort2");
				DWRUtil.addOptions("sort2",fectureArray);
				DWRUtil.addOptions("sort2", map_data);
				var item = document.getElementById("sort2").length;
				if (item == 0) {
					document.getElementById("sort2").style.display = "none";
				} else {
					document.getElementById("sort2").style.display = "inline";
				}
		 }
	 });
	}
}

function setTherdClass(val) {
	var cust_id = document.getElementById("cust_id").value;
	Ti_organizeInfo.getOrganizeByUpId(cust_id, val, setSort3);
}
function setSort3(map_data) {
  var up_org_id = document.getElementById("sort2").value;
  var cust_id = document.getElementById("cust_id").value;
	if (map_data != null) {
		Ti_organizeInfo.checkChildren(cust_id,up_org_id,function(ret){
		 if(ret == "0"){
		 }else{
		 	 	DWRUtil.removeAllOptions("sort3");
				DWRUtil.addOptions("sort3",fectureArray);
				DWRUtil.addOptions("sort3", map_data);
				var item = document.getElementById("sort3").length;
				if (item == 0) {
					document.getElementById("sort3").style.display = "none";
				} else {
					document.getElementById("sort3").style.display = "inline";
				}
		 }
	 });
	}
}

function submitValue(){
	
	var user_name = trim(document.getElementById("user_name").value);
	if(user_name == ""){
		alert("请填写用户名！");
		document.getElementById("user_name").focus();
		return false;
	}
	if(escape(user_name).indexOf("%u")!=-1) { 
  	alert("用户名不能为中文或全角字符！");
  	document.getElementById("user_name").value = "";
  	document.getElementById("user_name").focus();
  	return false; 
  } 
	
	if(trim(document.getElementById("real_name").value) == ""){
		alert("请填写真实姓名！");
		document.getElementById("real_name").focus();
		return false;
	}
	
	var passwd = document.getElementById("passwd").value;

	var chemPasswd = /^(([A-Z])+|([a-z]+)|(\d+)){6,20}$/;

	if(passwd == ""){
		alert("请填写用户密码！");
		document.getElementById("passwd").focus();
		return false;
	}

	if(!chemPasswd.test(passwd)){
			
			alert("只允许数字和英文字母，请重新输入！");

			document.getElementById('passwd').focus();

			return false;

	}
	
	if(document.getElementById("c_passwd").value == ""){
		alert("请填写确认密码！");
		document.getElementById("c_passwd").focus();
		return false;
	}
	
	if(document.getElementById("passwd").value != document.getElementById("c_passwd").value ){
		alert("两次输入的密码不一致！");
		document.getElementById("c_passwd").value = "";
		document.getElementById("c_passwd").focus();
		return false;
	}
	
	Ti_adminInfo.checkUserName(document.getElementById("user_name").value,function(data){
			if(data == 1){
				alert("用户名已存在！");
				document.getElementById("user_name").value = "";
				document.getElementById("user_name").focus();
				return false;
			}else{
				var org_id = "";
				if(document.getElementById("sort1").value!=""){
					org_id += document.getElementById("sort1").value + "|";
				}
				if(document.getElementById("sort2").value!="" && document.getElementById("sort2").value!="请选择"){
					org_id += document.getElementById("sort2").value + "|";
				}
				if(document.getElementById("sort3").value!="" && document.getElementById("sort3").value!="请选择"){
					org_id += document.getElementById("sort3").value + "|";
				}
				if(org_id == ""){
					alert("请选择部门！");
					document.getElementById("sort1").focus();
					return false;
				}
				document.getElementById("org_id").value = org_id;
				
				var linkSize = document.getElementById("linkSize").value;
				var link_no = "";
				for(var i = 0;i<linkSize;i++){
					if(document.getElementById("role_code" + i).checked == true){
						link_no += document.getElementById("role_code"+i).value + "|";
					}
				}
				
				document.getElementById("role_code").value = link_no;
				if(link_no == ""){
					alert("请选择角色！");
					return false;
				}
				
				var email = document.getElementById("email");
			 var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
			 if(email !=null && email.value !="")
			 {
			   if(!myreg.test(email.value))
				 {
			     alert('请输入有效的E_mail！');
			     document.getElementById("email").focus();
			     return false;
				 }
				}
		
				var cellphone = document.getElementById("cellphone");
				var myreg1=/^\d{11,12}$/;
				if(cellphone !=null && cellphone.value !="")
				{
					if(!myreg1.test(cellphone.value))
					{
					   alert('请输入有效的手机号码！');
					   document.getElementById("cellphone").focus();
					   return false;
					}
				}
				
				var phone = document.getElementById("phone");
				var myreg2 =/^\d{7,8}$/;
				if(phone !=null && phone.value !="")
				{
					if(myreg2.search(phone.value)==-1)
					{
					   alert('请输入有效的电话号码！');
					   document.getElementById("phone").focus();
					   return false;
					}
				}
				
				var fax = document.getElementById("fax");
				if(fax !=null && fax.value !="")
				{
					if(!myreg2.test(fax.value))	
					{
					   alert('请输入有效的传真号码!');
					   document.getElementById("phone").focus();
					   return false;
					}
				}

				var qq = document.getElementById("qq");
				var myreg3 =/^\d/;
				if(qq !=null && qq.value !="")
				{
					if(!myreg3.test(qq.value))	
					{
					   alert('QQ号只能是数字!');
					   document.getElementById("qq").focus();
					   return false;
					}
				}

				var msn = document.getElementById("msn");
			 if(msn !=null && msn.value !="")
			 {
			   if(!myreg.test(msn.value))
				 {
			     alert('请输入有效的MSN！');
			     document.getElementById("msn").focus();
			     return false;
				 }
				}
				
				document.addForm.submit();
			}
		});	
	
}

function selectAll(){
	var checkall = document.getElementById("checkall");
	var listsize = document.getElementById("listsize").value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById("checkone"+i).checked = true;
		}else{
			document.getElementById("checkone"+i).checked = false;
		}
	}
}

function delIndexInfo( val ){
	var listsize = document.getElementById("listsize").value;
	var pkid_string = "";
	for(var i=0;i<listsize;i++){
		if(document.getElementById("checkone"+i).checked){
			pkid_string += document.getElementById("checkone"+i).value+"|";
		}
	}
	
	document.getElementById("pkid").value = pkid_string;
	if(pkid_string == ""){
		alert("请至少选择一条!");
		return false;
	}else{
		if( val == "1"){
			document.indexForm.action="/doTradeReg.do";
			document.getElementById("user_state").value="1";
			document.getElementById("bpm_id").value="1242";
			if(window.confirm("确认禁用吗?")){
				document.indexForm.submit();
			}
		}
		if( val == "2"){
			document.indexForm.action="/doTradeReg.do";
			document.getElementById("user_state").value="0";
			document.getElementById("bpm_id").value="1241";
			if(window.confirm("确认启用吗?")){
				document.indexForm.submit();
			}
		}
		if( val == "3"){
			document.indexForm.action="/doTradeReg.do";
			document.getElementById("bpm_id").value="2290";
			if(window.confirm("确认删除吗?")){
				document.indexForm.submit();
			}
		}
	}	
	
}


 function search(){
	var sort1 = document.getElementById("sort1").value;
	var sort2 = document.getElementById("sort2").value;
	var sort3 = document.getElementById("sort3").value;
	var org = "";
	if(sort1 != "请选择" && sort1!=""){
			 org = sort1  + "|";
	}
	if(sort2 != "请选择" && sort2!=""){
		   org=  sort1 +"|"+ sort2+"|";
	}
	if(sort3 != "请选择" && sort3!=""){
		   org = sort1 + "|" +  sort2 + "|" + sort3+"|";
	}
 	document.getElementById("org").value = org;
	document.indexForm.submit();

} 


function submitValues(){
	

	if(trim(document.getElementById("real_name").value) == ""){
		alert("请填写真实姓名！");
		document.getElementById("real_name").focus();
		return false;
	}
		
	if(document.getElementById("org_id").value == ""){
		var org_id = "";
		if(document.getElementById("sort1").value!=""){
			org_id += document.getElementById("sort1").value + "|";
		}
		if(document.getElementById("sort2").value!="" && document.getElementById("sort2").value!="请选择"){
			org_id += document.getElementById("sort2").value + "|";
		}
		if(document.getElementById("sort3").value!="" && document.getElementById("sort3").value!="请选择"){
			org_id += document.getElementById("sort3").value + "|";
		}
		if(org_id == ""){
			alert("请选择部门！");
			document.getElementById("sort1").focus();
			return false;
		}
		document.getElementById("org_id").value = org_id;
	}
	var linkSize = document.getElementById("linkSize").value;
	var link_no = "";
	for(var i = 0;i<linkSize;i++){
		if(document.getElementById("role_code" + i).checked == true){
			link_no += document.getElementById("role_code"+i).value + "|";
		}
	}
	
	document.getElementById("role_code").value = link_no;
	if(link_no == ""){
		alert("请选择角色！");
		return false;
	}
	
	var email = document.getElementById("email");
			 var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
			 if(email !=null && email.value !="")
			 {
			   if(!myreg.test(email.value))
				 {
			     alert('请输入有效的E_mail！');
			     document.getElementById("email").focus();
			     return false;
				 }
				}

	var cellphone = document.getElementById("cellphone");
				var myreg1=/^(13\d|15[89])\d{5}(\d{3}|\*{3})$/;
				if(cellphone !=null && cellphone.value !="")
				{
					if(!myreg1.test(cellphone.value))
					{
					   alert('请输入有效的手机号码！');
					   document.getElementById("cellphone").focus();
					   return false;
					}
				}
				
				var phone = document.getElementById("phone");
				var myreg2 =/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
				if(phone !=null && phone.value !="")
				{
					if(!myreg2.test(phone.value))	
					{
					   alert('请输入有效的电话号码!');
					   document.getElementById("phone").focus();
					   return false;
					}
				}

				var fax = document.getElementById("fax");
				if(fax !=null && fax.value !="")
				{
					if(!myreg2.test(fax.value))	
					{
					   alert('请输入有效的传真号码!');
					   document.getElementById("phone").focus();
					   return false;
					}
				}

				var qq = document.getElementById("qq");
				var myreg3 =/^\d/;
				if(qq !=null && qq.value !="")
				{
					if(!myreg3.test(qq.value))	
					{
					   alert('QQ号只能是数字!');
					   document.getElementById("qq").focus();
					   return false;
					}
				}

				var msn = document.getElementById("msn");
			 if(msn !=null && msn.value !="")
			 {
			   if(!myreg.test(msn.value))
				 {
			     alert('请输入有效的MSN！');
			     document.getElementById("msn").focus();
			     return false;
				 }
				}
	
	document.addForm.submit();
	
}

function selectAll(){
	var checkall = document.getElementById("checkall");
	var listsize = document.getElementById("listsize").value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById("checkone"+i).checked = true;
		}else{
			document.getElementById("checkone"+i).checked = false;
		}
	}
}

function ChangeOrg(){
	document.getElementById("org1").style.display = "none";
	document.getElementById("org2").style.display = "inline";
	document.getElementById("org_id").value = "";
}

function delOneNews(val){
  if(window.confirm('确认删除吗？')){
 	  window.location.href='/doTradeReg.do?pkid='+val+'&bpm_id=2290'; 
  } 
}

function submitPasswd(){
	if(document.getElementById("passwd").value == ""){
		alert("请填写用户密码！");
		document.getElementById("passwd").focus();
		return false;
	}
	
	if(document.getElementById("c_passwd").value == ""){
		alert("请填写确认密码！");
		document.getElementById("c_passwd").focus();
		return false;
	}
	
	if(document.getElementById("passwd").value != document.getElementById("c_passwd").value ){
		alert("两次输入的密码不一致！");
		document.getElementById("c_passwd").value = "";
		document.getElementById("c_passwd").focus();
		return false;
	}
	
	document.addForm.submit();
}

 